home *** CD-ROM | disk | FTP | other *** search
/ Robotics & Artificial Int…3 (Professional Edition) / Robotics & Artificial Intelligence Tools 2003 (Professional Edition).iso / neural network tool and application / nsinstall.exe / data1.cab / DLLCust_Files / FILE / BINFLOAT.C < prev    next >
Encoding:
C/C++ Source or Header  |  2002-03-08  |  1.8 KB  |  62 lines

  1. // Dynamic link library implementation of binary file translator with offset and duration
  2.  
  3. #include "NSDLL.h" 
  4. #include <stdio.h> 
  5.  
  6. /**********************************/
  7. /* Read next sample from file */
  8. __declspec(dllexport) BOOL performFile(
  9.     DLLData        *instance,    // Pointer to instance data (may be NULL)
  10.     FILE        *file,         // Pointer to the opened file
  11.     NSFloat        *sample        // Location to place next sample
  12.     )
  13. {
  14.     int duration = getIntParameter(instance, 2, 1);
  15.     int *durationCount = (int*)getUserData(instance);
  16.     if ((!duration || ((*durationCount)++ < duration)) && fread(sample, sizeof(NSFloat), 1, (FILE*)file))
  17.         return TRUE;
  18.     *durationCount = 0;
  19.     fclose((FILE*)file);
  20.     return FALSE;
  21. }
  22.  
  23. /********************************************/
  24. /* Open and the file and return its pointer */
  25. __declspec(dllexport) FILE *openFile(DLLData *instance, const char *filePath)
  26. {
  27.     NSFloat *buffer;
  28.     FILE *file = fopen(filePath, "rb");
  29.     int offset = getIntParameter(instance, 1, 1);
  30.  
  31.     if (offset) {
  32.         buffer = malloc(offset*sizeof(NSFloat));
  33.         fread(buffer, sizeof(NSFloat), offset, file);
  34.         free(buffer);
  35.     }
  36.     return file;
  37. }
  38.  
  39. /******************************************/
  40. /* Management of instance data (OPTIONAL) */
  41.  
  42. __declspec(dllexport) DLLData *allocFile(
  43.     DLLData    *oldInstance    // Pointer to the last instance if reallocating
  44.     )
  45. {
  46.     DLLData *instance = allocDLLInstance(oldInstance);
  47.     setParameterName(instance, 1, 1, "Offset", FALSE);
  48.     setIntParameter(instance, 1, 1, 0, FALSE);
  49.     setParameterName(instance, 2, 1, "Duration", FALSE);
  50.     setIntParameter(instance, 2, 1, 0, FALSE);
  51.     setUserData(instance, calloc(1,sizeof(int)));
  52.     return instance;
  53. }
  54.  
  55. __declspec(dllexport) void freeFile(DLLData *instance)
  56. {
  57.     if (getUserData(instance))
  58.         free((int*)getUserData(instance));
  59.     freeDLLInstance(instance);
  60. }
  61.  
  62.